package com.yuwei.visit

import android.util.Log
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.yuwei.base.BaseActivity
import com.yuwei.base.path.RouterPath
import com.yuwei.visit.adapter.VisitAdapter
import com.yuwei.visit.adapter.VisitStatusAdapter
import com.yuwei.visit.databinding.ActivityVisitBinding
import com.yuwei.visit.viewmodel.VisitVIewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = RouterPath.MODULE_VISIT_ACTIVITY)
class VisitActivity : BaseActivity<ActivityVisitBinding,VisitVIewModel>() {
    private val statusList : List<String> = listOf("全部状态","已完成","待审核","已通过","已拒绝")
    private val visitStatusAdapter = VisitStatusAdapter()
    private val visitAdapter = VisitAdapter()
    override fun initView() {
        vm.getVisitList()
        binding.visitBack.setOnClickListener {
            finish()
        }
        visitStatusAdapter.data.addAll(statusList)
        visitStatusAdapter.notifyDataSetChanged()
        binding.visitStatusRv.adapter = visitStatusAdapter
        binding.visitStatusRv.layoutManager = LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false)
        visitStatusAdapter.setOnItemClickListener { adapter, view, position ->
            visitStatusAdapter.setPosition(position)
            visitStatusAdapter.notifyDataSetChanged()
        }
        binding.visitListRv.adapter = visitAdapter
        binding.visitListRv.layoutManager = LinearLayoutManager(this)
        visitAdapter.setOnItemClickListener { adapter, view, position ->
        }
        binding.visitAdd.setOnClickListener {
            ARouter.getInstance().build(RouterPath.MODULE_ADD_VISIT_ACTIVITY).navigation()
        }
    }

    override fun initData() {
        vm.getVisitListSuccess.observe(this){
            Log.d("TAG", "initData: ${it[0].visitorName}")
            visitAdapter.data.addAll(it)
            visitAdapter.notifyDataSetChanged()
        }
    }

}